<template>
  <div >
    <el-form v-show="showFrom" onsubmit="return false" >

      <el-col :span="6" style="margin-top: 10px">
        <el-form-item>
          <h2>文章标题</h2>
          <el-input v-model="input" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-col>


      <el-col :span="6" style="margin-top: 10px">
        <el-form-item>
          <h2>文章类型</h2>
          <el-select v-model="value" placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item>
          <h2>当前时间</h2>
          <h2>{{ nowDate }}</h2>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item>
      <textarea id="mytextarea" name="info">


      </textarea>
        </el-form-item>
      </el-col>

      <el-form-item>
        <el-button round @click="onSubmit">上传</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  name: "index",
  data() {
    return {
      showFrom: true,
      context: '',
      options: [{
        value: '金融类型',
        label: '金融类型'
      }, {
        value: '体育类型',
        label: '体育类型'
      }, {
        value: '时事新闻',
        label: '时事新闻'
      }, {
        value: '新冠疫情',
        label: '新冠疫情'
      }],
      value: '',
      input: '',
      nowDate: "", // 当前日期
    }
  },
  mounted() {
    this.currentTime()
    tinymce.init({
      selector: '#mytextarea',
      mobile: {
        theme: 'mobile'
      },
      height: 300,
      language: 'zh_CN', //设置语言
      plugins: 'image,save', //设置图片插件
      toolbar: 'image|save', //菜单图片
      images_upload_url: 'meituan/meituan/ImgPost', //上传后端地址
      images_upload_base_path: 'meituan/img', //见下面注解
      skin: 'oxide-dark', //样式

    })
  },
  methods: {
    currentTime() {
      setInterval(this.formatDate, 500);
    },
    formatDate() {
      let date = new Date();
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      let week = date.getDay(); // 星期
      let weekArr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
      let hour = date.getHours(); // 时
      hour = hour < 10 ? "0" + hour : hour; // 如果只有一位，则前面补零
      let minute = date.getMinutes(); // 分
      minute = minute < 10 ? "0" + minute : minute; // 如果只有一位，则前面补零
      let second = date.getSeconds(); // 秒
      second = second < 10 ? "0" + second : second; // 如果只有一位，则前面补零
      this.nowDate = `${year}/${month}/${day} ${hour}:${minute}:${second} ${weekArr[week]}`;
    },
    //保存按钮触发的事件
    onSubmit() {
      //获取到富文本编辑框里的内容
      let info = tinymce.get('mytextarea').getContent()
      console.log(info);
      console.log(this.value)
      console.log(this.input)
      console.log(this.nowDate)
      let formData = new FormData()
      formData.append("info", info)
      formData.append("title", this.input)
      formData.append("type", this.value)
      formData.append("time", this.nowDate)
      this.$axios.post("meituan/meituan/esTest", formData).then(
          r => {
            console.log(r.data)
          }
      )
    },
    init() {
      // this.token=localStorage.getItem("token")
      // console.log(this.token)
      // this.$axios.get("api2/findByMenu/"+this.token).then(
      //     r=>{
      //       let listData=r.data;
      //       this.quanxian1=listData[0].menuAddress
      //       this.quanxian2=listData[1].menuAddress
      //     }
      // )
      this.$axios.get("meituan/meituan/findByAll").then(
          r => {
            console.log(r.data)
            this.tableData = r.data;
          }
      )
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    dateManager(number) {
      if (number == 1) {
        this.loginMovie = true
        this.tianmaofindOrder = false
        this.movie = false
        this.dianyingOrder = false
      }
      if (number == 2) {
        this.tianmaofindOrder = true
        this.loginMovie = false
        this.movie = false
        this.dianyingOrder = false
      }
      if (number == 3) {
        this.movie = true
        this.tianmaofindOrder = false
        this.loginMovie = false
        this.dianyingOrder = false
      }
      if (number == 4) {
        this.dianyingOrder = true
        this.movie = false
        this.tianmaofindOrder = false
        this.loginMovie = false
      }
    }
  }
  //   show: async function () {
  //     let httpurl = 'http://localhost:8081';
  //     // this.listData = await ajaxGet(httpurl + '/film/findByAll');
  //     await this.$axios.get('api2/film/findByAll').then(
  //         r=>{
  //           this.listData=r.data;
  //         }
  //     )
  //   },
  //   add: async function(id){
  //     let info=""
  //     await this.$axios.get('tm/tianmao/add?id='+id).then(
  //         r=>{
  //           info=r.data;
  //         }
  //     )
  //     if (info=='ok'){
  //       alert("购买成功")
  //       location.href="/"
  //     }
  //   }
  // }
}
</script>


<style scoped>

</style>